package com.ruoyi.web.course;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.course.vo.SExamOptionVo;
import com.ruoyi.course.service.ISExamOptionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 学生考试选项Controller
 *
 * @author ruoyi
 * @date 2024-12-03
 */
@Api(tags = "学生考试选项Controller")
@RestController
@RequestMapping("/course/s_e_option")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class SExamOptionController extends BaseController {

    private final ISExamOptionService sExamOptionService;

    @ApiOperation("查询学生考试选项列表")
    @PreAuthorize("@ss.hasPermi('course:s_e_option:list')")
    @GetMapping("/list")
    public TableDataInfo<SExamOptionVo> list(SExamOptionVo entity) {
        return sExamOptionService.queryList(entity);
    }

    @ApiOperation("查询学生考试选项所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(SExamOptionVo entity) {
        return AjaxResult.success("查询成功", sExamOptionService.queryAll(entity));
    }

    @ApiOperation("导出学生考试选项列表")
    @PreAuthorize("@ss.hasPermi('course:s_e_option:export')")
    @Log(title = "学生考试选项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SExamOptionVo entity) {
        List<SExamOptionVo> list = sExamOptionService.queryAll(entity);
        ExcelUtil<SExamOptionVo> util = new ExcelUtil<>(SExamOptionVo.class);
        util.exportExcel(response, list, "学生考试选项数据");
    }

    @ApiOperation("获取学生考试选项详细信息")
    @PreAuthorize("@ss.hasPermi('course:s_e_option:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", sExamOptionService.queryById(id));
    }

    @ApiOperation("新增学生考试选项")
    @PreAuthorize("@ss.hasPermi('course:s_e_option:add')")
    @Log(title = "学生考试选项", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody SExamOptionVo entity) {
        return toAjax(sExamOptionService.save(entity));
    }

    @ApiOperation("修改学生考试选项")
    @PreAuthorize("@ss.hasPermi('course:s_e_option:edit')")
    @Log(title = "学生考试选项", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody SExamOptionVo entity) {
        return toAjax(sExamOptionService.updateById(entity));
    }

    @ApiOperation("删除学生考试选项")
    @PreAuthorize("@ss.hasPermi('course:s_e_option:remove')")
    @Log(title = "学生考试选项", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sExamOptionService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
